Skip to content

gh-144991: Use runtime JIT threshold in _testinternalcapi#145496

Merged
corona10 merged 4 commits intopython:mainfrom
corona10:gh-144991
Mar 5, 2026
Merged

gh-144991: Use runtime JIT threshold in _testinternalcapi#145496
corona10 merged 4 commits intopython:mainfrom
corona10:gh-144991

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Mar 4, 2026

@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label Mar 4, 2026
@corona10
Copy link
Member Author

corona10 commented Mar 4, 2026

@markshannon @Fidget-Spinner

TIER2_THRESHOLD was hardcoded using the JUMP_BACKWARD_INITIAL_VALUE,
which doesn't reflect runtime overrides.
This fix intends to read the actual value from interp->opt_config at module init instead.

if (PyModule_Add(module, "TIER2_THRESHOLD",
// + 1 more due to one loop spent on tracing.
PyLong_FromLong(JUMP_BACKWARD_INITIAL_VALUE + 2)) < 0) {
PyLong_FromLong(interp->opt_config.jump_backward_initial_value + 2)) < 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may use PyLong_FromUnsignedLong() since the member is unsigned (uint16_t). Suggestion to use shorter lines:

    PyInterpreterState *interp = PyInterpreterState_Get();
    // + 1 more due to one loop spent on tracing.
    unsigned long threshold = interp->opt_config.jump_backward_initial_value + 2;
    if (PyModule_Add(module, "TIER2_THRESHOLD",
                        PyLong_FromUnsignedLong(threshold)) < 0) {
        return 1;
    }

@vstinner
Copy link
Member

vstinner commented Mar 4, 2026

"aarch64-pc-windows-msvc/msvc (Debug)" failed with:

Assertion failed: index < _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES, file C:\a\cpython\cpython\Objects\typeobject.c, line 323

The recent change commit e6c3c04 added a new static type to static_types array. I suppose that #define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 201 should be updated.

@corona10 corona10 requested a review from vstinner March 4, 2026 14:26
Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/* For now we hard-code this to a value for which we are confident
all the static builtin types will fit (for all builds). */
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 201
#define _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES 202
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a new static type was added recently, and JIT tests crash or fail with an assertion error without this change: #145496 (comment)

@corona10 corona10 merged commit 8b54313 into python:main Mar 5, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir topic-JIT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants